import sys
from PyQt6.QtWidgets import QApplication
from PyQt6.QtGui import QPainter, QColor, QPainterPath, QIcon, QLinearGradient, QPen
from PyQt6.QtCore import Qt

def create_app_icon():
    """创建一个更现代美观的应用图标"""
    # 创建一个 64x64 的图标
    from PyQt6.QtGui import QPixmap
    icon_size = 64
    pixmap = QPixmap(icon_size, icon_size)
    pixmap.fill(Qt.GlobalColor.transparent)
    
    # 创建画家
    painter = QPainter(pixmap)
    painter.setRenderHint(QPainter.RenderHint.Antialiasing)
    
    # 绘制主背景 - 使用渐变色
    gradient = QLinearGradient(0, 0, icon_size, icon_size)
    gradient.setColorAt(0, QColor("#1976D2"))  # 深蓝色
    gradient.setColorAt(1, QColor("#2196F3"))  # 蓝色
    painter.setBrush(gradient)
    painter.setPen(Qt.PenStyle.NoPen)
    painter.drawEllipse(2, 2, icon_size-4, icon_size-4)
    
    # 添加轻微的阴影效果
    shadow_color = QColor(0, 0, 0, 40)
    painter.setBrush(shadow_color)
    painter.drawEllipse(4, 5, icon_size-8, icon_size-8)
    
    # 绘制文档主体 - 使用渐变白色
    doc_gradient = QLinearGradient(0, 0, 24, 0)
    doc_gradient.setColorAt(0, QColor("#FFFFFF"))
    doc_gradient.setColorAt(1, QColor("#F5F5F5"))
    painter.setBrush(doc_gradient)
    
    # 创建带有圆角的文档形状
    doc_path = QPainterPath()
    doc_path.addRoundedRect(18, 12, 28, 38, 3, 3)
    painter.drawPath(doc_path)
    
    # 绘制文档折角 - 更平滑美观
    corner_path = QPainterPath()
    corner_path.moveTo(37, 12)
    corner_path.lineTo(46, 12)
    corner_path.lineTo(46, 21)
    corner_path.arcTo(37, 12, 9, 9, 0, 90)
    painter.drawPath(corner_path)
    
    # 反光效果
    highlight = QPainterPath()
    highlight.addRoundedRect(19, 13, 3, 36, 1.5, 1.5)
    painter.setBrush(QColor(255, 255, 255, 40))
    painter.drawPath(highlight)
    
    # 绘制文档线条 - 更美观的间距
    painter.setPen(QColor("#90CAF9"))  # 浅蓝色线条
    painter.drawLine(23, 22, 41, 22)
    painter.drawLine(23, 29, 41, 29)
    painter.drawLine(23, 36, 35, 36)
    painter.drawLine(23, 43, 30, 43)
    
    # 添加一个微妙的高光
    painter.setPen(QPen(QColor(255, 255, 255, 60), 1.5))
    painter.drawArc(5, 5, icon_size-10, icon_size-10, 40*16, 150*16)
    
    painter.end()
    return pixmap

def create_and_save_multiple_sizes():
    """创建多种尺寸的图标并保存为ICO文件"""
    app = QApplication(sys.argv)
    
    # 创建基础图标
    icon = QIcon()
    
    # 生成多种尺寸的图标
    sizes = [16, 32, 48, 64, 128, 256]
    for size in sizes:
        # 创建新图标并调整大小
        pixmap = create_app_icon().scaled(
            size, size, 
            Qt.AspectRatioMode.KeepAspectRatio, 
            Qt.TransformationMode.SmoothTransformation
        )
        icon.addPixmap(pixmap)
        
        # 保存各个尺寸的PNG文件用于检查
        pixmap.save(f"app_icon_{size}.png")
    
    # 保存为ICO文件
    pixmap = create_app_icon()
    pixmap.save("app.ico")
    
    print("图标已保存为 app.ico 和各种尺寸的 PNG 文件")

if __name__ == "__main__":
    create_and_save_multiple_sizes() 